package renguanyu.app.auth4fx.util;

import atlantafx.base.controls.Notification;
import atlantafx.base.theme.Styles;
import atlantafx.base.util.Animations;
import javafx.animation.Timeline;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.util.Duration;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.material2.Material2OutlinedAL;
import renguanyu.app.auth4fx.App;

public class NotificationUtil {

    public static void show(String message){
        notification.setMessage(message);
        notification.setVisible(true);
        Timeline in = Animations.slideInDown(notification, Duration.millis(500));
        in.playFromStart();
    }

    public static void hiden(){
        Timeline out = Animations.slideOutUp(notification, Duration.millis(500));
        out.playFromStart();
        out.setOnFinished(f -> notification.setVisible(false));
    }

    public static Notification notification = new Notification();
    public static void initObj() {
        notification.setOnClose(e -> hiden());
        notification.setGraphic(new FontIcon(Material2OutlinedAL.HELP_OUTLINE));
        notification.getStyleClass().addAll(Styles.ACCENT, Styles.ELEVATED_1);
        notification.setPrefHeight(Region.USE_PREF_SIZE);
        notification.setMaxHeight(Region.USE_PREF_SIZE);
        StackPane.setAlignment(notification, Pos.TOP_RIGHT);
        StackPane.setMargin(notification, new Insets(10, 10, 0, 0));
        notification.setVisible(false);
        App.rootPane.getChildren().add(notification);
    }

}
